<?
include_once "gblinclude.lib";
include_once "delcheck.lib";


$objName = $_GET["obj_name"];
$objId = UnRegisterID($_GET["obj_id"]);
$delCheck = CDelCheck::GetInstance();

if ($_POST["process_flag"])
{
	$listUrl = CObjInfo::GetInstance()->objInfos[$objName]->listUrl;
	$delInView = $_POST["del_in_view"];
	$delCheck->delete($objName, $objId);
	echo '<script>';
		if (!IsEmptyString($delInView))
			echo '
			var delInView = '.$delInView.';';
		else
			echo '
			var delInView = 0;';
		echo '
			window.close();
			if (delInView == 1)
				window.opener.location = "'.$listUrl.'";
			else
				window.opener.location.reload();
		</script>';
	exit;
}

$resArr = $delCheck->checkRelObjs($objName, $objId);

$layoutFactory = new CLayoutFactory();

$header = $layoutFactory->getHeader();
$tail = $layoutFactory->getTail();
$body = createContent();

$js = createJs();

echo $header.$js.$body.$tail;


function createContent()
{
	global $resArr;
	
	$content = '';
	$content .= '<form id="form_data" action="#" method="POST">';
		$content .= '<table  border="0" cellspacing="0" cellpadding="0" width="100%">';
			$content .= '<tr height="40">';
				$content .= '<td valign="middle" class="td_content_title" style="color:#ff0000">&nbsp;Delete Alert</td>';
			$content .= '</tr>';
			$content .= '<tr>';
				$content .= '<td>';
					$content .= '<table width="100%" border="1"  cellpadding="0" cellpadding="0"  class="edit_table_style" style="margin-top:5px">';
					$content .= '<tr>';
						$content .= '<td class="edit_table_style_td_1" style="color:#ff0000;padding-left:5px" >The Records below will be deleted either.</td>';
					$content .= '</tr>';
					$content .= '<tr>';
						$content .= '<td class="edit_table_style_td_2" style="padding-left:6px"><ul>';
						foreach($resArr as $msgObj)
						{
							$content .= '<li style="padding-top:5px">'.$msgObj.'</li>';
						}
						$content .= '</ul></td>';
					$content .= '</tr>';
					$content .= '</table>';
				$content .= '</td>';
			$content .= '</tr>';
			$content .= '<tr height="35px">';
			$content .= '<td  align="right" style="padding-right:5px">&nbsp;';
				$content .= CUIControls::GetHidden("process_flag", 1);
				$content .= CUIControls::GetHidden("del_in_view", $_GET["del_in_view"]);
				$content .= CUIControls::GetNormalButton("btn_save", "Delete", "button_style", "onclick=\"submitForm();\"").'&nbsp;';
				$content .= CUIControls::GetNormalButton("btn_cancel", "Cancel", "button_style", "onclick=\"window.close();\"");
			$content .= '</td>';
					$content .= '</tr>';
		$content .= '</table>';
	$content .= '</form>';

	return $content;
}

function createJs()
{
	$script = '
		<script>
			function submitForm()
			{
				var frmEle = document.getElementById("form_data");
				frmEle.submit();
			}
		</script>
		';

	return $script;
}
?>

